<?php

use Cframe\Url;
use Cframe\Session;
use Cframe\Cache;
if (!function_exists("url")){
    function url($controller = '',$arr = array()){
        $url = call_user_func(array(new Url,"CreateUrl"),$controller,$arr);
        return $url;
    }
}

if (!function_exists("surl")){
    function surl($controller = ''){
        $url = call_user_func(array(new Url,"Build"),$controller);
        return $url;
    }
}

if (!function_exists("session")){
    function session($name,$value = ''){
        if (empty($value)){
            return Session::get($name);
        }
        if (is_null($value)){
            Session::del($name);
            return false;
        }
        if (is_null($name)){
            Session::clean();
            return false;
        }
        Session::set($name,$value);
    }
}

if (!function_exists("C")){
    function C($name,$value = ''){
        if (empty($value)){
            return Cache::load($name);
        }
        Cache::set($name,$value);
    }
}

if (!function_exists("model")){
    function model($name){
        $dug = debug_backtrace();
        $class = $dug[1]['class'];
        $class = explode(APP_NAME,$class)[0];
        $class = $class . BIND_MODEL . "\\" . ucfirst($name);
        if (class_exists('\\'.$class)) {
            $class = "\\" . $class;
            return new $class();
        }
    }
}
use Cframe\Log;
if (!function_exists("loging")){
    function loging($type,$msg = ''){
        Log::write($type,$msg);
    }
}